<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text"> <button>点击</button>
    <div></div>
    <script>
        // // trim 方法只去除字符串首尾的空格
        // var str = "   an dy  ";
        // console.log(str);
        // // 返回的是新字符串
        // var newStr = str.trim();
        // console.log(newStr);

        var input = document.querySelector("input");
        var btn = document.querySelector("button");
        var div = document.querySelector("div");
        btn.addEventListener("click", function() {
            var str = input.value.trim();
            if (str === "") {
                alert("请输入内容");
            } else {
                div.innerText = str;
            }
        })
    </script>
</body>

</html>